package com.company.cloud.sdk.core.base;

import com.company.cloud.sdk.core.constant.SdkReturnEnum;

public class BaseSdkResponse {
    private String returnCode;
    private String returnMsg;

    public BaseSdkResponse() {
    }

    public static BaseSdkResponse error() {
        return error(SdkReturnEnum.SYSTEM_ERROR.getCode(), SdkReturnEnum.SYSTEM_ERROR.getMsg());
    }

    public static BaseSdkResponse error(String msg) {
        return error(SdkReturnEnum.SYSTEM_ERROR.getCode(), msg);
    }

    public static BaseSdkResponse error(String code, String msg) {
        BaseSdkResponse result = new BaseSdkResponse();
        result.setReturnCode(code);
        result.setReturnMsg(msg);
        return result;
    }

    public static BaseSdkResponse error(SdkReturnEnum sdkReturnEnum) {
        BaseSdkResponse result = new BaseSdkResponse();
        result.setReturnCode(sdkReturnEnum.getCode());
        result.setReturnMsg(sdkReturnEnum.getMsg());
        return result;
    }

    public static <T extends BaseSdkResponse> T error(T t) {
        return error(SdkReturnEnum.SYSTEM_ERROR.getCode(), SdkReturnEnum.SYSTEM_ERROR.getMsg(), t);
    }

    public static  <T extends BaseSdkResponse> T error(String code, String msg, T t) {
        t.setReturnCode(code);
        t.setReturnMsg(msg);
        return t;
    }

    public static <T extends BaseSdkResponse> T error(String msg, T t) {
        return error(SdkReturnEnum.SYSTEM_ERROR.getCode(), msg, t);
    }

    public static <T extends BaseSdkResponse> T error(SdkReturnEnum sdkReturnEnum, T t) {
        return error(sdkReturnEnum.getCode(), sdkReturnEnum.getMsg(), t);
    }

    public static BaseSdkResponse ok() {
        BaseSdkResponse result = new BaseSdkResponse();
        result.setReturnCode(SdkReturnEnum.SUCCESS.getCode());
        result.setReturnMsg(SdkReturnEnum.SUCCESS.getMsg());
        return result;
    }


    public static <T extends BaseSdkResponse> T ok(T t) {
        t.setReturnCode(SdkReturnEnum.SUCCESS.getCode());
        t.setReturnMsg(SdkReturnEnum.SUCCESS.getMsg());
        return t;
    }

    public String getReturnCode() {
        return this.returnCode;
    }

    public String getReturnMsg() {
        return this.returnMsg;
    }

    public void setReturnCode(final String returnCode) {
        this.returnCode = returnCode;
    }

    public void setReturnMsg(final String returnMsg) {
        this.returnMsg = returnMsg;
    }

}
